package com.zhaowb.springcloud.admin.rest;

import com.github.pagehelper.PageHelper;
import com.zhaowb.springcloud.admin.biz.GateLogBiz;
import com.zhaowb.springcloud.admin.entity.GateLog;
import com.zhaowb.springcloud.common.msg.TableResultResponse;
import com.zhaowb.springcloud.common.rest.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

/**
 * Created with IDEA
 *
 * @author zhaowb
 * @date 2018/11/6 11:05
 */
@Controller
@RequestMapping(value = "gateLog")
public class GateLogController extends BaseController<GateLogBiz, GateLog> {

    @ResponseBody
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public TableResultResponse<GateLog> page(@RequestParam(defaultValue = "10") int limit, @RequestParam(defaultValue = "1") int offet, String name) {
        Example example = new Example(GateLog.class);
        if (StringUtils.isNotBlank(name)) {
            example.createCriteria().andLike("menu", "%" + name + "%");
        }
        int count = baseBiz.selectCountByExample(example);
        PageHelper.startPage(offet, limit);
        return new TableResultResponse<>(count, baseBiz.selectByExample(example));
    }
}

